#!/usr/bin/python
# -*- coding: UTF-8 -*-

class Solution:
    def romanToInt(self, s: str) -> int:
        dic = {
            'I': 1,
            'X': 10,
            'C': 100,
            'M': 1000,
            'V': 5,
            'L': 50,
            'D': 500
        }

        result = 0

        for index, char in enumerate(s):
            if index + 1 < len(s) and dic[char] < dic[s[index+1]]:
                result -= dic[char]
            else:
                result += dic[char]

        return result


if __name__ == '__main__':
    solution = Solution()
    testcases = {
        'I': 1,
        'II': 2,
        'III': 3,
        'IV': 4,
        'IX': 9,
        'XX': 20,
        'XXX': 30,
        'X': 10,
        'V': 5,
        'XXVII': 27,
        'M': 1000,
        'IX': 9,
        'LVIII': 58,
        'C': 100,
        'CC': 200,
        'CCC': 300,
        'MC': 1100,
        'MCMXCIV': 1994
    }

    for case in testcases:
        value = testcases[case]
        print('Case [%s], expect = %s' % (case, value))
        result = solution.romanToInt(case)
        if result == value:
            print('=> PASS result = %s' % result)
        else:
            print('=> FAIL, result = %s' % result)
